package poker;
import java.awt.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import java.io.*;
import java.util.*;

import javax.swing.*;

public class ServerSettingsGUI extends DefaultSettingsPanelGUI 
{	
	public JLabel l1, l2;
	public JTextField t1, t2;
	private SettingsGUI sg;
	
	public ServerSettingsGUI(SettingsGUI sg2)
	{
		this.sg = sg2;
		l1 = new JLabel("Poort: ");
		l2 = new JLabel("Servernaam");
		t1 = new JTextField(15); t2 = new JTextField(15);
		this.add(l1); this.add(t1);
		this.add(l2); this.add(t2);
	}

	@Override
	public void cancel() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean ok() 
	{
		if(!(t1.getText().matches("\\d{1,5}")))
		{
			JOptionPane.showMessageDialog(null, "you did not specify the port correctly");
			
		}
		if(!t2.getText().matches("\\w{1,15}"))
		{
			JOptionPane.showMessageDialog(this, "This is not a valid name");
			
		}
		if(t1.getText().matches("\\d{1,5}") && t2.getText().matches("\\w{1,15}"))
		{	try
			{
				Properties p = new Properties();
				p.load( new FileInputStream("settings.ini") );
				p.setProperty("Port", t1.getText());
				p.setProperty("ServerName", t2.getText());
				p.store( new FileOutputStream("settings.ini"), "" );
			}catch(IOException fe)
			{
				
			}
			
		}

		return false;
	}

}
